home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / POINTERS.SWG / 0008_TREEHITE.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  667b  |  27 lines

  1. {
  2. Authors: Chet Kress and Jerome Tonneson
  3.  
  4. >Help !!! I need a Function or Procedure in standard pascal that will
  5. >calculate the height of a binary tree. It must be able to calculate the
  6. >height of the tree if the tree is either balanced, unbalanced or full.
  7. >The Procedure must be recursive.
  8.  
  9. Here are the only two Functions you will need.
  10. }
  11.  
  12. Function Max(A, B : Integer) : Integer;
  13. begin {Max}
  14.   If A > B then
  15.     Max := A;
  16.   else
  17.     Max := B;
  18. end; {Max}
  19.  
  20. Function Height (Tree : TreeType) : Integer;
  21. begin {Height}
  22.   If Tree = Nil then
  23.     Height := 0
  24.   else
  25.     Height := Max(Height(Tree^.Right), Height(Tree^.Left)) + 1;
  26. end; {Height}
  27.